package com.blinddate.action;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;

import com.blinddate.orm.BdUser;
import com.blinddate.service.BdUserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {
	
	private String phonenumber;
	private String password;
	private BdUserService bdUserService;
	
	public BdUserService getBdUserService() {
		return bdUserService;
	}

	public void setBdUserService(BdUserService bdUserService) {
		this.bdUserService = bdUserService;
	}

	public String getPhonenumber() {
		return phonenumber;
	}

	public void setPhonenumber(String phonenumber) {
		this.phonenumber = phonenumber;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	public String UserLogin() throws NoSuchAlgorithmException, UnsupportedEncodingException{
		String hql = "from BdUser as a where a.phonenumber = '" 
				+ "'18256980177'" 
				+ "' and a.password = '" 
				+ "'123456'";
		BdUser bdUser = bdUserService.loadByHql(hql);
		if(bdUser !=null ){
			ActionContext.getContext().getSession().remove("bdUser");
			ActionContext.getContext().getSession().put("bdUser", bdUser);
			return SUCCESS;
		}
		return SUCCESS;
	}

}
